-- SERVER APPLE

// Creates something... honestly forgot why I name these now
if (not file.IsDir("TDM/FirstK","DATA")) then
    file.CreateDir("TDM/FirstK")
end
if not(file.Exists("TDM/FirstK/FirstK.txt","DATA")) then
	file.Write("TDM/FirstK/FirstK.txt", 0)
	print("[TDM] Wrote file : TDM/Timer/FirstK.txt")
end
file.Write("TDM/FirstK/FirstK.txt", 0)

function KSDeathTDM( ply, wep, killer )
if killer == ply then
	elseif killer:Team() == ply:Team() then
		else
		if tonumber(file.Read("TDM/FirstK/FirstK.txt","DATA")) == 0 then
		file.Write("TDM/FirstK/FirstK.txt", 1)
			umsg.Start( "TDM_Player_IS_FK", killer )
			umsg.End()
		end
		local GKSP = (killer:GetPData("KSPoints") + 1)
		GKSTTDM = killer:GetPData("KSPointsTime")
		killer:SetPData("KSPoints", GKSP)
		ply:SetPData("KSPoints", 0)
		if GKSP == 2 || GKSP == "2" then
		MsgN("LAST DEATH TIME: "..(math.Round(CurTime()) - GKSTTDM))
			if (math.Round(CurTime()) - GKSTTDM) <= 5 then
			umsg.Start( "TDM_Player_IS_DK", killer )
			umsg.End()
			else
			killer:SetPData("KSPoints", 1)
			end
		end
		if GKSP == 3 || GKSP == "3" then
		MsgN("LAST DEATH TIME: "..(math.Round(CurTime()) - GKSTTDM))
			if (math.Round(CurTime()) - GKSTTDM) <= 5 then
			umsg.Start( "TDM_Player_IS_TK", killer )
			umsg.End()
			else
			killer:SetPData("KSPoints", 1)
			end
		end
		if GKSP == 5 || GKSP == "5" then
		MsgN("LAST DEATH TIME: "..(math.Round(CurTime()) - GKSTTDM))
			if (math.Round(CurTime()) - GKSTTDM) <= 4 then
			umsg.Start( "TDM_Player_IS_KC", killer )
			umsg.End()
			killer:SetPData("KSPoints", 0)
			elseif (math.Round(CurTime()) - GKSTTDM) <= 10 then
			umsg.Start( "TDM_Player_IS_KS", killer )
			umsg.End()
			killer:SetPData("KSPoints", 0)
			else
			killer:SetPData("KSPoints", 1)
			end
		end	
		killer:SetPData("KSPointsTime", math.Round(CurTime()))
--		MsgN("CURRENT TIME: "..math.Round(CurTime()))
--		MsgN("KSPOINTTIME: "..GKSTTDM)
	end
end
hook.Add( "PlayerDeath", "KSDeathTDM", KSDeathTDM ) 
